package com.stud.common.core.domain;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.stud.common.interfaces.SqlHelpJavaBean;
import com.stud.common.interfaces.ValidateInterface;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * Entity基类
 *
 * @author Stud
 */
@Getter
@Setter
public class Entity implements Serializable, Cloneable, ValidateInterface, SqlHelpJavaBean {

    protected Long id;

    protected String delFlag = "0";

    @TableField(fill = FieldFill.INSERT)
    protected String createBy;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    protected LocalDateTime createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    protected String updateBy;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    protected LocalDateTime updateTime;

    protected String remark;

    /**
     * 请求参数
     */
    @TableField(exist = false)
    @JsonIgnore
    protected Map<String, Object> params;

    public Map<String, Object> getParams() {
        if (params == null) {
            params = new HashMap<>();
        }
        return params;
    }

    public Object clone() {
        Object obj = null;
        try {
            obj = super.clone();
        } catch (CloneNotSupportedException ignored) {
        }
        return obj;
    }

}
